﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Hicap.AuthorizationServer.Migrations
{
    public partial class Fix01 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "SubordinateCompanyId",
                table: "User",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "Company",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    IsActive = table.Column<bool>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    TenantName = table.Column<string>(maxLength: 48, nullable: true),
                    CompanyCode = table.Column<string>(maxLength: 24, nullable: false),
                    CompanyName = table.Column<string>(maxLength: 48, nullable: false),
                    CompanyType = table.Column<int>(nullable: false),
                    IsCertified = table.Column<bool>(nullable: false),
                    License = table.Column<string>(maxLength: 24, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Company", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_User_SubordinateCompanyId",
                table: "User",
                column: "SubordinateCompanyId");

            migrationBuilder.AddForeignKey(
                name: "FK_User_Company_SubordinateCompanyId",
                table: "User",
                column: "SubordinateCompanyId",
                principalTable: "Company",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_User_Company_SubordinateCompanyId",
                table: "User");

            migrationBuilder.DropTable(
                name: "Company");

            migrationBuilder.DropIndex(
                name: "IX_User_SubordinateCompanyId",
                table: "User");

            migrationBuilder.DropColumn(
                name: "SubordinateCompanyId",
                table: "User");
        }
    }
}